package com.lightheart.sphr.xiaobinggan.customchannel

import android.content.Context
import android.os.Bundle
import android.support.design.widget.BottomSheetBehavior
import android.support.design.widget.BottomSheetDialog
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import butterknife.ButterKnife
import butterknife.OnClick
import com.lightheart.sphr.xiaobinggan.R
import com.lightheart.sphr.xiaobinggan.utils.UiUtils
import kotlinx.android.synthetic.main.channel_dialog.*

/**
 *    Author :hongliang
 *    E-mail : 13717858152@163.com
 *    Date   : 2021/3/103:02 PM
 *    Desc   :
 *    Version: 1.0.0
 */
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class ChannelDialog(context: Context) :
    BottomSheetDialog(context, R.style.user_default_dialog), View.OnClickListener {

    private var mChannelListener: ChannelListener? = null

    init {
        setContentView(R.layout.channel_dialog)
        ButterKnife.bind(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val screenWidth = UiUtils.getScreenHeidth(context)
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (screenWidth-35f).toInt())
//        window.setWindowAnimations(R.style.dialog_anim)
        iv_cross.setOnClickListener {
            dismiss()
        }
    }

    @OnClick(R.id.iv_cross)
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.iv_cross -> {
                dismiss()
            }
        }
    }

    override fun show() {
        super.show()
        window.apply {
            val mContent = decorView.findViewById<FrameLayout>(R.id.design_bottom_sheet)
            val orginLayoutParams = mContent.layoutParams
            orginLayoutParams.height=ViewGroup.LayoutParams.MATCH_PARENT
            mContent.layoutParams=orginLayoutParams
            val mDialogBehavior = BottomSheetBehavior.from(mContent)
            mDialogBehavior.setState(BottomSheetBehavior.STATE_EXPANDED)
        }
    }

    fun setOnClickChannelListener(listener: ChannelListener) {
        mChannelListener = listener
    }

    interface ChannelListener {
        fun onClickSure()
    }
}